package com.tuomaxu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class SendEmailController {

    @Autowired
    private JavaMailSender javaMailSender;

    @GetMapping("/send/{email}/{code}")
    public boolean send(@PathVariable String email,@PathVariable String code){

        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("登录验证码");
        message.setFrom("tuomaxu@qq.com");
        message.setTo(email);
        message.setText("验证码："+code);
        try {
            javaMailSender.send(message);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return  false;
        }
    }
}
